package GUIadapter;

import java.util.List;
import javax.swing.table.AbstractTableModel;
import ModelLayer.Customer;

@SuppressWarnings("serial")
public class TableCustomerAdapterModel extends AbstractTableModel
{
	private final String[] columnHeader= {"Index","Navn","Adresse","Postnr","By","Phone","E-mail","Rabat"};
	
	private List<Customer> customerList;

	public TableCustomerAdapterModel(List<Customer> customerList) {
		this.customerList = customerList;
	}
	
	@Override
	public String getColumnName(int column) {
		return columnHeader[column];
	}

	@Override
	public int getColumnCount() {
		return columnHeader.length; //depends on amount of getters for a supplier eg.: "getName()"... very ugly
	}

	@Override
	public int getRowCount() {
		return customerList.size();
	}

	@Override
	public Object getValueAt(int row, int col) {
		Customer customer = customerList.get(row);
		switch(col) {
			case 0: return new Integer(row);//index
			case 1: return customer.getName();
			case 2: return customer.getAddress();
			case 3: return customer.getCity();
			case 4: return customer.getPostal();
			case 5: return customer.getEmail();
			case 6: return customer.getPhone();
			case 7: return new Integer(customer.getCraftsmanDiscount());
		}
		return null; //should never reach here..!
	}	
}
